<?php
//头部
function do_html_header($title)
{
?>
    <html>

    <head>
        <title><?php echo $title; ?></title>
        <style>
            body {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 13px
            }

            li,
            td {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 13px
            }

            hr {
                color: #3333cc;
                width: 300;
                text-align: left
            }

            a {
                color: #000000
            }

            .logo {
                width: 100px;
                height: 100px;
                overflow: hidden;
            }

            .logo img {
                height: 100px;
            }

            .title a {
                text-decoration: none;
            }

            .title a:hover {
                text-decoration: underline;
            }

            #priority3 a {
                font-weight: bold;
                color: #D00;
            }

            #priority2 a {
                color: #06B;
            }

            #priority1 a {
                color: #3D9F0E;
            }

            #priority0 a {
                color: #1A3959;
            }
        </style>
    </head>

    <body>
        <h1>兰州大学点餐平台</h1>
        <?php
        if ($title) {
            do_html_heading($title);
        }
    }
    //尾部
    function do_html_footer()
    {
        ?>
    </body>

    </html>
<?php
    }
    //标题
    function do_html_heading($heading)
    {
?>
    <h2><?php echo $heading; ?></h2>
<?php
    }
    //网站信息提示
    function display_site_info()
    {
?>
    <ul>
        <li>欢迎使用兰州大学点餐平台</li>
        <li>希望本平台可以给您带来良好的用餐体验</li>
    </ul>
<?php
    }
    //显示登录表单
    function display_login_form()
    {
?>
    <p><a href="register_form.php">点我注册</a></p>
    <form method="post" action="check.php">
        <table bgcolor="#FFFF99">
            <tr>
                <td colspan="2">请登录：</td>
            <tr>
                <td>校园卡号：</td>
                <td><input type="text" name="sno" /></td>
            </tr>
            <tr>
                <td>密码：</td>
                <td><input type="password" name="passwd" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="登录" />
                </td>
            </tr>
            <tr>
                <td colspan="2"><a href="forgot_form.php">忘记密码？</a></td>
            </tr>
            <tr>
                <td colspan="2"><a href="modify_form.php">修改密码！</a></td>
            </tr>
        </table>
    </form>
<?php
    }
    //显示注册表单
    function display_registration_form()
    {
?>
    <form method="post" action="register_new.php">
        <table bgcolor="#FFFF99">
            <tr>
                <td>请输入校园卡号：</td>
                <td><input type="text" name="sno" maxlength="12" /></td>
            </tr>
            <tr>
                <td>请输入密码 <br />(6到16个字符):</td>
                <td valign="top"><input type="password" name="passwd" maxlength="16" /></td>
            </tr>
            <tr>
                <td>再次输入密码以确认:</td>
                <td><input type="password" name="passwd2" maxlength="16" /></td>
            </tr>
            <tr>
                <td>请输入手机号：</td>
                <td><input type="text" name="tel" maxlength="11" /></td>
            </tr>
            <tr>
                <td colspan=2 align="center">
                    <input type="submit" value="注册">
                </td>
            </tr>
        </table>
    </form>
<?php
    }
    //显示修改个人信息表单
    function display_change_personal_information_form()
    {
?>
    <form method="post" action="change_personal_information.php" enctype="multipart/form-data" id="file_upload">
        <table width="250" cellpadding="1" cellspacing="0" bgcolor="#FFFF99">
            <tr>
                <td>更改头像：</td>
                <td><input type="file" name="user_logo" accept="image/gif, image/jpeg, image/png, image/jpg" /></td>
            </tr>
            <tr>
                <td>更改性别：</td>
                <td><input type="text" name="user_sex" maxlength="4" /></td>
            </tr>
            <tr>
                <td>更改生日：</td>
                <td><input type="date" name="user_age" /></td>
            </tr>
            <tr>
                <td>更改电话：</td>
                <td><input type="text" name="tel" maxlength="11" /></td>
            </tr>
            <tr>
                <td>更改QQ号：</td>
                <td><input type="text" name="user_qq" maxlength="10" /></td>
            </tr>
            <tr>
                <td>更改email：</td>
                <td><input type="text" name="user_email" maxlength="30" /></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="确认" />
                </td>
            </tr>
        </table>
    </form>
<?php
    }
    //显示忘记密码表单
    function display_forgot_form()
    {
?>
    <form method="post" action="forgot_password.php">
        <table width="250" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
            <tr>
                <td>请输入校园卡号：</td>
                <td><input type="text" name="username" maxlength="12" /></td>
            </tr>
            <tr>
                <td colspan=2 align="center">
                    <input type="submit" value="Change password" />
                </td>
            </tr>
        </table>
    </form>
<?php
    }
    //显示历史订单
    function display_history_order()
    {
?>
    <table width="100%" cellpadding="2" cellspacing="0" bgcolor="#cccccc">
        <tr>
            <td>订单号</td>
            <td>菜品名称</td>
            <td>菜品数量</td>
            <td>菜品单价</td>
            <td>菜品总价</td>
            <td>订单时间</td>
            <td>订单状态</td>
        </tr>
    </table>
<?php
    }
    //显示订餐首页
    function display_shopping_index()
    {
?>
    <div align='center'>
        <h3>点餐系统首页</h3>
        <table border="1" cellspacing="1">
            <th width="100px" style="background:#66ccff;">商标</th>
            <th width="200px" style="background:#66ccff;">商家</th>
            <th width="400px" style="background:#66ccff;">简介</th>
            <th width="100px" style="background:#66ccff;">总销量</th>
            <?php
            require_once('db_fns.php');
            $conn = db_connect();
            $page = 1;
            $pagesize = 10;
            $sql = "call sp_show_merchant_details_by_page({$page},{$pagesize})";
            $result = $conn->query($sql);
            while ($row = $result->fetch_array()) { ?>
                <tr>
                    <td>
                        <div class="logo"><img src="data\merchant_logo\<?php echo $row['logo'] ?>" title="<?php echo '店名: ' . $row['name'] . ' 联系方式: ' . $row['tel'] . ' 地址: ' . $row['address'] ?>"></div>
                    </td>
                    <td style="text-align: center" class="title" id="priority<?php echo $row['priority'] ?>"><a href='merchant.php?mid=<?php echo $row['mid'] ?>'><?php echo $row['name'] ?></a></td>
                    <td>
                        <div style="margin: 5px 10px 5px 10px"><?php echo $row['introduction'] ?></div>
                    </td>
                    <td style="text-align: center"><?php echo $row['sales'] ?></td>
                </tr>
            <?php
            }
            ?>
        </table>
        <a href=cart.php>查看餐车</a>
        <a href=user_center.php>返回首页</a>
    </div>
<?php
    }
    //显示购物车
    function display_cart()
    {
?>
    <?php
        require_once('db_fns.php');
        $conn = db_connect();
        if (isset($_SESSION['flag']) && $_SESSION['flag'] != 0) {
            foreach ($_SESSION as $key => $value) {
                if ($key != 'uid' && $key != 'valid_user' && $key != 'flag') {
                    $sql = "select * from merchant_dishes where did=" . $value;
                    $result = $conn->query($sql);
                    if ($row = $result->fetch_array())
                        echo "<br>菜品序号：" . $value . " | 菜品名：" . $row['name'] . " | 价格：" . $row['price'] . " | <a href = del.php?did=" . $value . ">移除</a>";
                }
            }
        } else {
            echo "您的购物车是空的，请先选择菜品";
        }
    ?>
    <br>
    <a href=index.php>继续点单</a>
    <br>
    <a href="order.php"> 提交订单</a>
<?php
    }
    //显示用户中心
    function display_user_center()
    {
?>
    <a href='index.php'>开始订餐</a><br>
    <a href='user_detail.php'>个人中心</a><br>
    <a href='history_order.php'>查看订单</a><br>
    <a href='logout.php'>退出登录</a><br>
<?php
    }
